var app = getApp();
var pageData = {
    data: {
        goods_box:[],
        showResult: false, //搜索结果展示
        itemStyle: 1, //商品列表显示方式 单列显示 1  双列显示 2
        res_data:[], //储存数据
        tab: 9,
        direction: 0,
        prevPage: 0,
        pageData: {},
        itemsList: [],
        history: [],
        inputContent: '',
        filterParam: {
            form: 'goods',
            id:0,
            page: 1,
            page_size: 10,
            sort_key: '',
            sort_direction: '',
            is_integral: '',
            idx_arr: {
                idx: '',
                idx_value: ''
            },
            search_value: '',
            region_id: ''
        },
        animationData: {},
        filter: false,
        locationList: [],
        DataUrl:'',
        DataObject:{},
        SelectFlag:0, //选择 状态
        GoodsAllMoney:0
    },
    onLoad: function (e) {

    },
    onShow: function () {  //生命周期函数--监听页面显示  每次跳转到此页面 就会调用
      this.setData({
        pageData: app.globalData.OrderList[0]
      })
      this.setData({
        itemsList: app.globalData.OrderList[0].info
      })
    },
    userShopping(){   //用户购物车
        var url = app.globalData.HOST + app.APILIST.getmyshopping;
        var data = {
            "data":{
            "userid":[app.globalData.UserInfo.id],
            "limit": app.globalData.goods_limit,
             }
        }
        if (app.globalData.UserInfo.id == undefined){
            wx.showToast({
                title: '请登录',
                image:'/images/jinggao.png',
                duration: 2000
            })
        }else{
            app.WxRequest(url,data,1,
                (res)=>{
                  this.data.res_data = res.data;
                  this.data.res_data.forEach((it)=>{
                    it.checked = false;
                    it.discount = (it.goods.price * it.goods_num) * app.globalData.UserInfo.rate;
                    it.price = it.goods.price * it.goods_num;
                    it.discount = it.discount.toFixed(2);
                    it.price = it.price.toFixed(2);
                  })
        },( ref )=>{
        });
    }
    },
    // getMoreItems: function (e) {  //下拉 事件
    //     let curPage = e.target.dataset.curpage;

    //     if (curPage < this.data.pageData.last_page) {
    //         this.data.filterParam.page = this.data.filterParam.page + 1;
    //         this.setData({prevPage: curPage});
    //         var url = app.globalData.HOST + app.APILIST.getmyshopping;
    //         var data =   {
    //             "data":{
    //                "userid":[app.globalData.UserInfo.id],
    //                "limit": app.globalData.goods_limit,
    //            }
    //         }
    //         app.WxRequest(url, data, this.data.filterParam.page,
    //             (res) =>{
    //             var list = [...this.data.itemsList,...res.data];
    //             this.data.res_data = list;
    //         this.setData({
    //             pageData: res
    //         })
    //         this.setData({
    //             itemsList: list
    //         })
    //     },( ref )=>{
    //             console.log(ref);
    //         });
    //     };
    // },





    purchase(){  //生成订单  
    var code = '';
    var pro = app.MyPromise((result,rf)=>{
      wx.getStorage({
        key: 'UserSession',
        success: function (res) {
          result(res.data.openid);
        },
        fail: function (rf){
        }
      });
    });
  
    pro.then((e)=>{  
      var url = app.globalData.HOST + app.APILIST.payOrder;
      var data = {
        "data": {
          "client": 'mini',
          "orderid": app.globalData.OrderList[0].id,
          "openid": e,
        }
      };
      app.WxRequest(url, data, 1,
        (res) => {
       var res_data = JSON.parse(res.data);
        wx.requestPayment({
        "timeStamp": res_data.timeStamp,
        "nonceStr": res_data.nonceStr,
        "package": res_data.package,
        "signType": "MD5",
        "paySign": res_data.paySign,
        "success": function (res) {
     
        },
        "fail": function (res) {
          
             }
          })
        }, (ref) => {
 
        });
    })
    },
    dataInitial: function () {
        app.pageDataInitial();
    },
    /**
 * 跳转到详情页
 */
    turnToDetail: function (e) {

      // let id = e.currentTarget.dataset.id;
      // app.turnToPage('/eCommerce/pages/goodsDetail/goodsDetail?goodsid=' + id);

    },
    onShareAppMessage: function (e) {
        return app.onPageShareAppMessage(e);
    },


};
Page(pageData);
